package org.springblade.modules.admin.vo;

import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.ObjectUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.springblade.modules.admin.enums.ElevatorMaintainStatusEnums;

import java.io.Serializable;
import java.util.Date;

/**
 * 维保电梯及当前责任关联关系详情VO
 * @author: Sharry
 * @createTime: 2023/2/11 8:42
 * @version: Version-1.0
 */
@Data
public class ElevatorRelationDetailVO implements Serializable {

	/**
	 * 电梯主键Id, 查询及关联依据
	 */
	private Long elevatorId;

	/**
	 * 梯号
	 */
	private String elevatorAddress;
	/**
	 * 项目名
	 */
	private String name;

	/**
	 * 项目详细地址
	 */
	private String address;

	/**
	 * 电梯运行状态
	 */
	private Integer isStop;

	/**
	 * 所属梯组
	 */
	private String group;

	/**
	 * 维保责任人
	 */
	private String users;

	/**
	 * 电梯年审类型 0-年审 1-非年审
	 */
	private Integer useType;

	/**
	 * 上一次维保签字日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	private Date previousPlanDate;

	/**
	 * 下一次保养计划日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	private Date nextPlanDate;

	/**
	 * 逾期日期
	 */
	@JsonFormat(pattern = "yyyy-MM-dd")
	private Date overdueDate;

	/**
	 * 逾期描述
	 */
	private String overdueDateDesc;

	private Integer maintainStatus;

	/**
	 * 在保情况
	 */
	private String maintainStatusDesc;

	public void setMaintainStatus(Integer maintainStatus) {
		this.maintainStatus = maintainStatus;
		if(ObjectUtil.isNotEmpty(maintainStatus)){
			this.maintainStatusDesc = ElevatorMaintainStatusEnums.getName(maintainStatus);
		}
	}

	public void setOverdueDate(Date overdueDate) {
		this.overdueDate = overdueDate;
		if(ObjectUtil.isNotEmpty(overdueDate)){
			Date now = DateUtil.parseDate(DateUtil.today());
			if(overdueDate.getTime() == now.getTime()){
				this.overdueDateDesc = "明天即将违规";
			}else if(overdueDate.getTime() > now.getTime()){
				this.overdueDateDesc = "正常";
			}else {
				long betweenDay = DateUtil.between(overdueDate, now, DateUnit.DAY);
				this.overdueDateDesc = "已违规（"+betweenDay+"）天";
			}
		}
	}
}
